/*
 日期：2025-06-03
 作者：lijj
 作用：测试消息量对应耗时，频繁发送消息测试[send]
 测试方式：sender 中启动线程，循环发送消息，在 receiver 中消息处理打印耗时
 测试详情：
    测试次数           测试时间
    100                0.572505 ms
    1000               5.51455 ms
    10000              42.6363 ms
    100000             428.223 ms
    200000             878.479 ms
    1000000            4494.15 ms
*/

#include <iostream>
#include <string>
#if defined(_WIN32)
#include <Windows.h>
#include <process.h>
#else
#include <unistd.h>
#endif
#include "mgnotify.h"
#include "center.hpp"
#include "sneder.h"
#include "receiver.h"

using namespace std;

void logo()
{
    cout << endl;
    cout << endl;
    cout << "  _________ __                        \n";  
    cout << " /   _____//  |_  ____   ____   ____     \n"; 
    cout << " \\_____  \\\\   __\\/  _ \\ /    \\_/ __ \\    \n"; 
    cout << " /        \\|  | (  <_> )   |  \\  ___/    \n"; 
    cout << "/_______  /|__|  \\____/|___|  /\\___  >  \n";
    cout << "        \\/                  \\/     \\/   \n";
    cout << endl;
    cout << endl;
}

void title()
{
    cout << endl;
    cout << "  日期：2025-05-30 \n";  
    cout << "  作者：lijj \n"; 
    cout << "  作用：测试消息量对应耗时，频繁发送消息测试[send] \n"; 
    cout << "  详情：单个消息发送者、接受者，在 sender 类中使用线程循环发送消息，receiver 中处理消息 \n"; 
    cout << endl;
}

void enter()
{
    logo();
    title();
    while(true) {
        string in;
        cin >> in;
        cout << "enter: " << in << endl;
        if(in == "quit")
            break;
    }
}

int main()
{
#if defined(_WIN32 )
    SetConsoleOutputCP(65001); // UTF-8 
    SetConsoleCP(65001);       // 输入也设为UTF-8 
#endif 
    thread t(enter);
#if defined(_WIN32)
    Sleep(100);
#else
    sleep(0.1);
#endif
    cout << "main thread id: " << t.get_id() << endl;
    receiver r1;
    sender s1;
    s1.start_thread(1000000);
    t.join();
    return 0;
}
